from django.db import models
from datetime import datetime

# Create your models here.
from django.contrib.auth.models import AbstractUser

# 自定义数据模型--继承与框架原本的用户模型
class User(AbstractUser):
    mobile = models.CharField("电话", max_length=11, unique=True)
    # address = models.CharField(max_length=350,blank=True,null=True) # 由于用户可能有多个收货地址所以就不一对一了。
    email = models.EmailField("邮箱", blank=True, null=True)
    sex = models.BooleanField("性别", default=True, blank=True, null=True)
    age = models.IntegerField("年龄", default=18, blank=True, null=True)

    class Meta:
        db_table = "cassoapi_users"
        verbose_name = "用户表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


class UserAddress(models.Model):
    objects = models.Manager()
    title = models.CharField("地址标题", max_length=100)
    add_time = models.DateTimeField("添加时间", default=datetime.now)
    address = models.CharField("用户地址", max_length=350)
    mobile = models.CharField("联系电话", max_length=11)
    contactname = models.CharField(max_length=50)
    is_defult = models.BooleanField(default=True)
    owner = models.ForeignKey(User, related_name="user", on_delete=models.CASCADE)

    class Meta:
        db_table = "cassoapi_users_address"
        verbose_name = "用户地址"
        verbose_name_plural = verbose_name


class UserAvatar(models.Model):
    objects = models.Manager()
    avatar = models.ImageField(upload_to="avatar/", blank=True, null=True)
    owner = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        db_table = "cassoapi_users_avatar"
        verbose_name = "用户头像"
        verbose_name_plural = verbose_name


class Logo(models.Model):
    objects = models.Manager()
    logo = models.ImageField(upload_to="logo/", blank=True, null=True)

    class Meta:
        db_table = "logo"
        verbose_name = "LOGO"
        verbose_name_plural = verbose_name
